<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>代理机构管理 - 沧州市文化广电和旅游局抽取招标代理机构管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="沧州市文化广电和旅游局抽取招标代理机构管理系统">
    <meta name="description" content="沧州市文化广电和旅游局抽取招标代理机构管理系统是一个基于Bootstrap v3.3.7的后台管理系统。">
    <meta name="author" content="mzl">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/jquery.resizableColumns.css">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
</head>

<body>

<div class="lyear-layout-web">

    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a href="index.html" >
                    <img src="images/logo1.png" style="margin-top: 0px;margin-bottom: 0px;" title="沧州市文化广电和旅游局抽取招标代理机构管理系统" alt="沧州市文化广电和旅游局抽取招标代理机构管理系统" />
                </a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item "> <a href="index.html"><i class="mdi mdi-home "></i> 后台首页</a> </li>
                        <li class="nav-item "> <a href="project-list.html"><i class="mdi mdi-format-align-justify"></i> 项目管理</a> </li>
                        <li class="nav-item active"> <a href="company-list.html"><i class="mdi mdi-file-outline"></i> 代理机构管理</a> </li>
                    </ul>
                </nav>

                <div class="sidebar-footer">
<!--                    <p class="copyright">Copyright &copy; 2023. <a target="_blank" href="#">gift</a> All rights reserved.</p>-->
                </div>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">
            <div style="text-align: center;">
                <a style="font-size: 30px;  color:black">
                    沧州市文化广电和旅游局抽取招标代理机构管理系统
                </a>
            </div>
            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 代理机构管理 - 代理机构列表 </span>
                    </div>

                    <ul class="topbar-right">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">
                                <span id="realName">admin </span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">
<!--                                <li> <a href="#"><i class="mdi mdi-account"></i> 个人信息</a> </li>-->
                                <li> <a href="edit_pwd.html"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
<!--                                <li> <a href="javascript:void(0)"><i class="mdi mdi-delete"></i> 清空缓存</a></li>-->
<!--                                <li class="divider"></li>-->
                                <li> <a href="#!" id="logout"><i class="mdi mdi-logout-variant"  ></i> 退出登录</a> </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
<!--                        <li class="dropdown dropdown-skin">-->
<!--                            <span data-toggle="dropdown" class="icon-palette"><i class="mdi mdi-palette"></i></span>-->
<!--                            <ul class="dropdown-menu dropdown-menu-right" data-stopPropagation="true">-->
<!--                                <li class="drop-title"><p>主题</p></li>-->
<!--                                <li class="drop-skin-li clearfix">-->
<!--                  <span class="inverse">-->
<!--                    <input type="radio" name="site_theme" value="default" id="site_theme_1" checked>-->
<!--                    <label for="site_theme_1"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="site_theme" value="dark" id="site_theme_2">-->
<!--                    <label for="site_theme_2"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="site_theme" value="translucent" id="site_theme_3">-->
<!--                    <label for="site_theme_3"></label>-->
<!--                  </span>-->
<!--                                </li>-->
<!--                                <li class="drop-title"><p>LOGO</p></li>-->
<!--                                <li class="drop-skin-li clearfix">-->
<!--                  <span class="inverse">-->
<!--                    <input type="radio" name="logo_bg" value="default" id="logo_bg_1" checked>-->
<!--                    <label for="logo_bg_1"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_2" id="logo_bg_2">-->
<!--                    <label for="logo_bg_2"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_3" id="logo_bg_3">-->
<!--                    <label for="logo_bg_3"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_4" id="logo_bg_4">-->
<!--                    <label for="logo_bg_4"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_5" id="logo_bg_5">-->
<!--                    <label for="logo_bg_5"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_6" id="logo_bg_6">-->
<!--                    <label for="logo_bg_6"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_7" id="logo_bg_7">-->
<!--                    <label for="logo_bg_7"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="logo_bg" value="color_8" id="logo_bg_8">-->
<!--                    <label for="logo_bg_8"></label>-->
<!--                  </span>-->
<!--                                </li>-->
<!--                                <li class="drop-title"><p>头部</p></li>-->
<!--                                <li class="drop-skin-li clearfix">-->
<!--                  <span class="inverse">-->
<!--                    <input type="radio" name="header_bg" value="default" id="header_bg_1" checked>-->
<!--                    <label for="header_bg_1"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_2" id="header_bg_2">-->
<!--                    <label for="header_bg_2"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_3" id="header_bg_3">-->
<!--                    <label for="header_bg_3"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_4" id="header_bg_4">-->
<!--                    <label for="header_bg_4"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_5" id="header_bg_5">-->
<!--                    <label for="header_bg_5"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_6" id="header_bg_6">-->
<!--                    <label for="header_bg_6"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_7" id="header_bg_7">-->
<!--                    <label for="header_bg_7"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="header_bg" value="color_8" id="header_bg_8">-->
<!--                    <label for="header_bg_8"></label>-->
<!--                  </span>-->
<!--                                </li>-->
<!--                                <li class="drop-title"><p>侧边栏</p></li>-->
<!--                                <li class="drop-skin-li clearfix">-->
<!--                  <span class="inverse">-->
<!--                    <input type="radio" name="sidebar_bg" value="default" id="sidebar_bg_1" checked>-->
<!--                    <label for="sidebar_bg_1"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_2" id="sidebar_bg_2">-->
<!--                    <label for="sidebar_bg_2"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_3" id="sidebar_bg_3">-->
<!--                    <label for="sidebar_bg_3"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_4" id="sidebar_bg_4">-->
<!--                    <label for="sidebar_bg_4"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_5" id="sidebar_bg_5">-->
<!--                    <label for="sidebar_bg_5"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_6" id="sidebar_bg_6">-->
<!--                    <label for="sidebar_bg_6"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_7" id="sidebar_bg_7">-->
<!--                    <label for="sidebar_bg_7"></label>-->
<!--                  </span>-->
<!--                                    <span>-->
<!--                    <input type="radio" name="sidebar_bg" value="color_8" id="sidebar_bg_8">-->
<!--                    <label for="sidebar_bg_8"></label>-->
<!--                  </span>-->
<!--                                </li>-->
<!--                            </ul>-->
<!--                        </li>-->
                        <!--切换主题配色-->
                    </ul>

                </div>
            </nav>

        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content"  style="margin-top: 50px">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <form class="pull-right search-bar" method="get" action="#!" role="form">
                                    <div class="input-group">
                                        <button class="btn btn-w-xs btn-primary" id="search">搜索</button>

                                        <div class="col-xs-8">
                                            <input class="form-control" type="text" id="company_name" name="companyName" placeholder="请输入代理机构名称" value="" />
                                        </div>
                                    </div>
                                </form>
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-primary m-r-5" href="#!" data-toggle="modal" data-target="#myModal"><i class="mdi mdi-plus"></i> 新增代理机构</a>
                                </div>
                                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="myModalLabel">新增代理机构</h4>
                                            </div>
                                            <div class="modal-body">
                                                <input class="noneDisplay" id="id" type="text"/>
                                                <div class="form-group">
                                                    <label class="col-xs-12" for="companyName">代理机构名称</label>
                                                    <div class="col-xs-12">
                                                        <input class="form-control" type="text" id="companyName" name="example-text-input" placeholder="请输入代理机构名称" value=""  />
                                                    </div>
                                                </div>
<!--                                                <div class="form-group">-->
<!--                                                    <label class="col-xs-12" for="companyCode">企业代码</label>-->
<!--                                                    <div class="col-xs-12">-->
<!--                                                        <input class="form-control" type="text" id="companyCode" name="example-text-input" placeholder="请输入企业代码" value=""  />-->
<!--                                                    </div>-->
<!--                                                </div>-->
                                                <div class="form-group">
                                                    <label class="col-xs-12" for="frName">代理机构法人</label>
                                                    <div class="col-xs-12">
                                                        <input class="form-control" type="text" id="frName" name="example-text-input" placeholder="请输入代理机构法人姓名" value=""  />
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-xs-12" for="companyAddr">代理机构地址</label>
                                                    <div class="col-xs-12">
                                                        <input class="form-control" type="text" id="companyAddr" name="example-text-input" placeholder="请输入代理机构地址" value=""  />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                                <button type="button" id="saveBtn" class="btn btn-primary">点击保存</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <div class="card-body" >

                                <div class="table-responsive">
                                    <table class="table table-bordered" data-resizable-columns-id="companyTable">
                                        <thead>
                                        <tr>
                                            <th class="noneDisplay">
                                                id
                                            </th>
                                            <th data-resizable-column-id="companyName">代理机构名称</th>
                                            <th data-resizable-column-id="frName">代理机构法人</th>
                                            <th data-resizable-column-id="companyAddr">代理机构地址</th>
                                            <th data-resizable-column-id="option" id="option-column" data-noresize>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="companyList">

                                        </tbody>
                                    </table>
                                </div>
                                <nav>
                                    <ul class="pagination" id="pageList">
                                    </ul>
                                </nav>
                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<!--时间选择插件-->
<script src="js/bootstrap-datetimepicker/moment.min.js"></script>
<script src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
<!--日期选择插件-->
<script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<!--消息提示-->
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>
<script type="text/javascript" src="js/login.js"></script>
<script type="text/javascript" src="js/store.js"></script>
<script type="text/javascript" src="js/jquery.resizableColumns.min.js"></script>
<script type="text/javascript">

    $(function(){
        $(".noneDisplay").hide()
        $("table").resizableColumns({
            store: window.store
        });
        $.ajax({
            type: "POST",
            url: "http://localhost:18600/sys/user/loginInfo",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.code === 200){
                    document.getElementById('realName').textContent = data.loginUser.realName;
                }
            },
            error: function(xhr, textStatus, errorThrown) {
                loginError(xhr,textStatus,errorThrown)
            }
        });
        $('#logout').click(function(){
            $.ajax({
                type: "POST",
                url: "http://localhost:18600/sys/user/logout",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (data.code === 200){
                        lightyear.notify('退出成功', 'success', 2000);
                        window.location.href="/admin/login.html"
                    }

                }
            });
        });
        $('.search-bar .dropdown-menu a').click(function() {
            var field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });

        $('#saveBtn').click(function(){
            lightyear.loading('show');
            $.ajax({
                type: "POST",
                url: "http://localhost:18600/gift/company/add",
                dataType: "json",
                data: JSON.stringify({companyName: $('#companyName').val(), frName: $('#frName').val(),companyAddr: $('#companyAddr').val(), id:$('#id').val()}),
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (data.code === 200){
                        lightyear.notify('保存成功', 'success', 2000);
                    }else {
                        lightyear.notify('保存失败,失败原因：'+ data.message, 'danger', 2000);
                    }
                    // 假设ajax提交操作
                    setTimeout(function() {
                        lightyear.loading('hide');
                        window.location.reload();
                    }, 1e3)
                },
                error: function(xhr, textStatus, errorThrown) {
                    loginError(xhr,textStatus,errorThrown)
                }
            });
        });
        list(getUrlParam("currentPage"), getUrlParam("companyName"));
        if (getUrlParam("companyName")!==null) {
            $('#company_name').val(getUrlParam("companyName"));
        }

        $('#search').click(function(){
            skipHtml(1,$("#company_name").val());
        });
    });
    function list(currentPage,companyName) {
        $.ajax({
            type: "POST",
            url: "http://localhost:18600/gift/company/page",
            dataType: "json",
            data: JSON.stringify({currentPage: currentPage, companyName: companyName}),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                var list = data.records;
                var total = data.total;
                if(total > 0) {
                    var size = data.size;
                    var current = data.current;
                    console.log(list)
                    for (var i = 0; i < list.length; i++) {

                        console.info(list[i]);
                        list[i].companyCode = list[i].companyCode === null || list[i].companyCode === "" ? "-" : list[i].companyCode;
                        list[i].frName = list[i].frName === null || list[i].frName === "" ? "-" : list[i].frName;
                        list[i].companyAddr = list[i].companyAddr === null || list[i].companyAddr === "" ? "-" : list[i].companyAddr;
                        list[i].companyName = list[i].companyName === null || list[i].companyName === "" ? "-" : list[i].companyName;
                        var str = '<tr> <td style="display: none">' + list[i].id + "</td><td>" + list[i].companyName + "</td><td>" + list[i].frName + "</td><td>" + list[i].companyAddr
                            + "</td> <td>"
                            + '<div class="btn-group"> <a class="btn btn-xs btn-default"  onclick="updateDetail(' + "'" + list[i].id + "'" + ')" title="编辑代理机构" data-toggle="modal" data-target="#myModal"><i class="mdi mdi-pencil"></i></a> <a class="btn btn-xs btn-default" onclick="deleteBill(' + "'" + list[i].id + "'" + ')" href="#!" title="删除代理机构" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a> </div></td> </tr>';
                        console.info(str);
                        $('#companyList').append(str);
                    }
                    var pre = current === 1 ? current : current - 1;
                    var totalPage = Math.ceil(total / size);
                    var next = current === totalPage ? current : current + 1;
                    var page = "";
                    if (current <= 1) {
                        page = page + '<li class="disabled">\n' + ' <a>\n';
                    } else {
                        page = page + '<li>\n' + ' <a onclick=skipHtml(' + pre + ',' + companyName + ')>\n';
                    }
                    page = page +
                        '                            <span><i class="mdi mdi-chevron-left"></i></span>\n' +
                        '                        </a>\n' +
                        '                        </li>';

                    if (total >= 0) {
                        var allPages = Math.ceil(total / size);
                        for (var i = 1; i <= allPages; i++) {
                            var href = "/project-list.html?currentPage=" + i;
                            if (i === current) {
                                page = page + '<li class="active"><a onclick=skipHtml(' + i + ',' + companyName + ')>' + i + '</a></li>';
                            } else {
                                page = page + '<li><a onclick=skipHtml(' + i + ',' + companyName + ')>' + i + '</a></li>';
                            }
                        }
                    }
                    if (current >= totalPage) {
                        page = page + '<li class="disabled">\n' + ' <a>\n';
                    } else {
                        page = page + '<li>\n' + ' <a onclick=skipHtml(' + next + ',' + companyName + ')>\n';
                    }
                    page = page +
                        '                    <span><i class="mdi mdi-chevron-right"></i></span>\n' +
                        '                </a>\n' +
                        '                </li>';
                    $('#pageList').append(page);
                }
            },
            error: function(xhr, textStatus, errorThrown) {
                loginError(xhr,textStatus,errorThrown)
            }
        });
    }

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return ""; //返回参数值
    }

    function updateDetail(id) {
        $.ajax({
            type: "GET",
            url: "http://localhost:18600/gift/company/byId?id=" + id,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.code === 200){
                    // $("#myModal").css('display','block').attr('class','modal fade in');

                    $("#myModalLabel").text("修改代理机构");
                    var project = data.data;
                    $("#id").val(project.id);

                    $('#companyName').val(project.companyName);
                    $('#companyAddr').val(project.companyAddr);
                    $('#frName').val(project.frName);
                }else {
                    lightyear.notify('无法修改,原因：'+ data.message, 'danger', 2000);
                }
            },
            error: function(xhr, textStatus, errorThrown) {
                loginError(xhr,textStatus,errorThrown)
            }
        });
    }

    function skipHtml(page,companyName) {
        if (companyName === "" || companyName == null||typeof (companyName) == "undefined" || companyName === "undefined") {
            window.location.href = "/admin/company-list.html?currentPage=" + page;
        } else {
            window.location.href = "/admin/company-list.html?currentPage=" + page + "&companyName=" +companyName;
        }
    }

    function deleteBill(id) {
        lightyear.loading('show');
        $.ajax({
            type: "POST",
            url: "http://localhost:18600/gift/company/delete?id=" + id,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.code === 200){
                    lightyear.notify('删除成功', 'success', 2000);
                }else {
                    lightyear.notify('删除失败,失败原因：'+ data.message, 'danger', 2000);
                }
                // 假设ajax提交操作
                setTimeout(function() {
                    lightyear.loading('hide');
                    if (data.code === 200){
                        window.location.reload();
                    }
                }, 1e3)
            },
            error: function(xhr, textStatus, errorThrown) {
                loginError(xhr,textStatus,errorThrown)
            }
        });
    }

    function outputmoney(value) {
        if (!value && value !== 0) return '-';
        var intPart = Number(value) | 0; //获取整数部分
        var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断

        var floatPart = ".00"; //预定义小数部分
        var value2Array = value.toString().split(".");

        //=2表示数据有小数位
        if (value2Array.length == 2) {
            floatPart = value2Array[1].toString(); //拿到小数部分

            if (floatPart.length == 1) { //补0,实际上用不着
                return intPartFormat + "." + floatPart + '0';
            } else {
                return intPartFormat + "." + floatPart;
            }
        } else {
            return intPartFormat + floatPart;
        }
    }
</script>
</body>
</html>